import { http } from '../utils/request.js'

// 用户注册
export const register = (data) => {
  return http.post('/auth/register', {
    username: data.username,
    password: data.password,
    email: data.email,
    phone: data.phone || ''
  })
}

// 用户登录
export const login = (data) => {
  return http.post('/auth/login', {
    username: data.username,
    password: data.password
  })
}

// 刷新令牌
export const refreshToken = (refreshToken) => {
  return http.post('/auth/refresh-token', {
    refreshToken
  })
}

// 验证用户信息（忘记密码前验证）
export const validateUserInfo = (data) => {
  return http.post('/auth/validate-user-info', {
    email: data.email,
    phone: data.phone
  })
}

// 忘记密码
export const forgetPassword = (data) => {
  return http.post('/auth/forget-password', {
    email: data.email,
    phone: data.phone,
    newPassword: data.newPassword,
    confirmPassword: data.confirmPassword
  })
}

// 统一导出认证API
export const authAPI = {
  register,
  login,
  refreshToken,
  validateUserInfo,
  forgetPassword
}
